home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / postmail.80 < prev    next >
Text File  |  1997-02-28  |  12KB  |  341 lines

  1. /* a sample of a SRE-FILTER "post-filter"
  2. This will mail a message to selected users, depending on the value
  3. of the request selector, or the client's IP address.
  4. For general notes on how  POSTFILT is called, see the bottom of this file.
  5.  
  6.     ----------------------- A Mail Notification Facility ----------------
  7.  
  8. This will automatically send "e-mail alerts" to specified recipients given specified events.
  9. It calls the SREF_MAILIT procedure.
  10.  
  11. It requires that a valid SMTP Gateway be available (the SMTP Gateway
  12. is set by running SRE-FILTER's configurator and modifying the SMTP_GATEWAY variable)
  13. Note that if you may be able to use OS/2's SENDMAIL program to use the server as
  14. an SMTP gateway (see the TCP/IP command reference documentation).
  15.  
  16. To use this routine, you will need to set up an "event" list.  The event list
  17. should contain the following information:
  18.  a)   What type of event to examine (client or request selector)
  19.  b)   The value that triggers a "match" (i.e.; a client's address, or a request for a particular file)
  20.  c)   The list of e-mail addresses to send "e-mail alerts" to
  21.  d)   An optional message to include in these alerts.
  22.  e)   An optional subject line
  23.  
  24. This routine uses the EVENTS.field.n  stem variable to store this event list.
  25.  
  26.   field should take one of 4 values
  27.      a)TYPE   : Either CLIENT or REQUEST (REQUEST is the "request selector")
  28.      b)VALUE : A numeric IP address, or a target request selector.  Either may contain * characters;
  29.               (either as domain wildcards or to signal "abbreviation matches")
  30.      c)RECIPIENTS: A space delimited list of e-mail  addresses
  31.      d)MESSAGE : An optional message.  It may contain CRLFs, and be quite long.
  32.      e)SUBJECT: An optional 1 line message to use as the SUBJECT.
  33.  
  34.    n is an integer value (that should run from 1.. "# of events")
  35.  
  36. You also must set EVENTS.0 equal to the "# of  events"
  37.  
  38. The algorithim works by:
  39.   From m=1.. to EVENTS.0
  40.       If EVENTS.TYPE.m=CLIENT, then see if client's numeric IP address
  41.           matches EVENTS.VALUE.m (with * acceptable as a wildcard)
  42.       If EVENTS.TYPE.m=REQUEST, see if the client's request selector matches EVENTS.VALUE.m,
  43.           (with * signalling that abbreviation matching should be used).
  44.           NOTE: The SEL variable contains the original request selector, before modifications
  45.                 by SRE-FILTER.  The match is against the entire request selector,
  46.                 not just the Action!  Thus, a SEL of FOO.HTM?this_one
  47.                 will NOT match a target of FOO.HTM (but will match FOO.HTM*)
  48.                 In comparision, exact matches (say,
  49.                 in the access_file) compare the action to the target -- so
  50.                 any ?xxx is ignored.
  51.  
  52.  
  53.   If either occurs
  54.       Create a note containing time,date, server name, client's name, SRE-FILTER status
  55.       message, and  EVENTS.MESSAGE.m
  56.            Note that EVENTS.MESSAGE.m is optional.
  57.       If EVENTS.SUBJECT.j is missing, a generic subject line is used.
  58.       Sent this note to each e-mail addresss listed in EVENT.RECIPIENTS.m
  59.  
  60. If there is not SMTP_GATEWAY specified, or EVENTS.0=0, then a short
  61. synopsis of the request is displayed using SAY
  62.  
  63. Note that there may be multiple matches; so that several different e-mail alerts (to
  64. different sets of e-mail addresses, some of which may contain common 
  65. addresses) may be generated by each call to this routine.
  66.  
  67. Example:
  68.  
  69. EVENTS.0=3
  70.  
  71. EVENTS.TYPE.1="CLIENT"
  72. EVENTS.VALUE.1="*.*.*.*"
  73. EVENTS.RECIPIENTS.1="bob@hisorg.net  jill@staff.agency.gov "
  74.      Note that EVENTS.MESSAGE.1 is not set
  75.  
  76. EVENTS.TYPE.2="REQUEST"
  77. EVENTS.VALUE.2="PROJECTS/PROJ1.HTM"
  78. EVENTS.RECIPIENTS.2="ANDREW@myorg.org"
  79. EVENTS.MESSAGE.2="A request for PROJ1 was recieved "
  80. events.subject.2=' PROJ1 Request '
  81.  
  82. EVENTS.TYPE.3="REQUEST"
  83. EVENTS.VALUE.2="\PUT_FILE*"
  84. EVENTS.RECIPIENTS.3="WEBMASTER@MYORG.ORG"
  85. EVENTS.MESSAGE.3="A file upload has been recieved! "||crlf||" You may want to check it?"
  86.   Note the use of CRLF to add a line feed to the message.
  87.  
  88. Note when EVENTS.TYPE.m=REQUEST:
  89.   all / are converted to \ (in both the SEL and EV*ENTS.VALUE.n), and
  90.   leading and trailing \ are stripped
  91.  
  92.             --------------------------------------------------
  93. */
  94.  
  95.  
  96.  
  97.   
  98. postfilt:
  99. CRLF = '0d0a'x
  100.  
  101. /*  ==============  INSERT  EVENTS list here   ================  */
  102.  
  103. events.0=0
  104.  
  105.  
  106. /* ============ DO NOT CHANGE BELOW HERE  ===================== */
  107. /* args sent here:
  108. post_filter_message,source0,request0,seloriginal,tempfile,
  109. servername,HOST_NICKNAME,used_file,thereferer,tcache
  110. */
  111.  
  112.  
  113. parse arg amessage,source,request,sel,tempfile,servername,host_nickname,used_file,thereferer
  114. parse var source serveraddr serverport transaction_number clientaddr clientport
  115.  
  116. GATEWAY=' '
  117. AFF='SREF_'||SERVERPORT||'_SMTP_GATEWAY'
  118. IF HOST_NICKNAME<>' ' THEN do
  119.    AFF2=AFF2||'.'||HOST_NICKNAME
  120.    GATEWAY=VALUE(AFF2,,'OS2ENVIRONMENT')
  121. end
  122. IF GATEWAY=' ' THEN
  123.   GATEWAY=VALUE(AFF,,'OS2ENVIRONMENT')
  124.  
  125.  
  126.  
  127. if gateway=0 then do                    /* if no gateway specified, do nothing */
  128.   call say_stuff
  129.   return ' '
  130. end
  131. if events.0=0 then do
  132.   call say_stuff
  133.   return ' '
  134. end
  135.  
  136.  
  137. sname=servername
  138. /* sname=servername()                info used below */
  139. cname=clientname()
  140. /* create ip number lookup table */
  141.    isnumip=verify(cNAME,'1234567890.')
  142.    if isnumip>0 then  do        /* is numeric ip */
  143.           astat=sockgethostbyaddr(clientaddr,'stuff.!')
  144.           cname=upper(stuff.!name)
  145.           if abbrev(cname,'STUFF.!')=1 then cname=clientaddr
  146.  
  147.    end
  148.  
  149.  
  150. atime=time()
  151. adate=date()
  152. CRLF = '0d0a'x
  153.  
  154. /* loop through events list .. */
  155. didit=0
  156. do jj=1 to events.0
  157.     ok=0
  158.     if events.TYPE.jj="CLIENT" then
  159.        ok=goodip(events.VALUE.jj,clientaddr)
  160.     else 
  161.       if events.type.jj='REQUEST' then do
  162.          ok=goodsel(upper(events.value.jj),upper(sel))
  163.      end
  164.     if ok=0 then iterate
  165.  
  166.     if didit=0 then
  167.        call pmprintf(" Using gateway at " gateway)
  168.     didit=1
  169.  
  170.  
  171. /* if here, a match occurred */
  172.    address_list=events.recipients.jj
  173.  
  174.    if symbol('events.subject.jj')='VAR' then  
  175.           asubject='Subject: '||events.subject.jj
  176.    else
  177.           asubject='Subject: Notification of WEB transaction  '
  178.  
  179.    themessage="Date: " || adate || ' ' ||atime
  180.    themessage=themessage||crlf||'From: WebServer@'||sname
  181.    themessage=themessage||crlf||asubject
  182.    themessage=themessage||crlf||'To: '||address_list||crlf
  183.  
  184.    themessage=themessage||crlf||'An e-mail alert from the Web Server at '||sname
  185.    themessage=themessage||crlf||"    Date of occurrence: " || adate || ' ' ||atime
  186.    themessage=themessage||crlf||'     Request by client: '|| cname
  187.    themessage=themessage||crlf||'      Request selector: '|| sel
  188.    themessage=themessage||crlf||' Server status message: '|| amessage
  189.  
  190.    if symbol('events.message.jj')='VAR' then  /* check for a mess up */
  191.       themessage=themessage||crlf||"Notes:"||crlf||events.message.jj||crlf
  192.    else
  193.       themessage=themessage||crlf
  194.  
  195.    foo=sref_mailit(address_list,themessage, gateway)
  196.    call pmprintf(" Event " jj ", MAILIT status: "foo)
  197.  
  198. end                     /* try next event */
  199.  
  200. return ' '
  201.  
  202. /* -----------------------------------------------------------------------*/
  203. /* see if match (or abbreviation match) the sel                          */
  204. /* -----------------------------------------------------------------------*/
  205. goodsel: procedure
  206. parse  arg asel,thesel
  207. asel=translate(asel) ; thesel=translate(thesel)
  208. asel=translate(asel,'\','/') ; asel=strip(asel,,'\')
  209. thesel=translate(thesel,'\','/') ; thesel=strip(thesel,,'\')
  210.  
  211. if asel=thesel then return 1   /* exact match */
  212. /* do abbreviation match? */
  213. if right(asel,1)<>'*' then return 0   /* nope */
  214. asel=left(asel,length(asel)-1)  /* try an abbreviation match */
  215.  
  216. return abbrev(strip(thesel),strip(asel))
  217.  
  218.  
  219. /* -----------------------------------------------------------------------*/
  220. /* see if matches one of a set of good ips (1 if yes)*/
  221. /* -----------------------------------------------------------------------*/
  222. goodip: procedure 
  223.  
  224. parse arg anips,cip0
  225. parse var anips ip.1 '.' ip.2 '.' ip.3 '.' ip.4
  226. parse var cip0 cip.1 '.' cip.2 '.' cip.3 '.' cip.4
  227. match=1
  228. do mm2=1 to 4
  229.       if ip.mm2="*" then iterate
  230.       if ip.mm2=cip.mm2 then iterate
  231.       match=0       /*if here, not a match */
  232.       leave
  233. end
  234. return match
  235.  
  236.  
  237. /* A simple transaction recorder (used if no SMTP_GATEWAY specified */
  238. say_stuff:
  239. say "  - - - - - "
  240. say time() ' ' date()
  241. say  "  Message= "  amessage
  242. say  " Source=  " source
  243. say   " Request= "  request
  244. say  " Sel = "  sel
  245. return 
  246.  
  247.  
  248.  
  249. /*******************************************************************
  250.  *******************************************************************
  251.   *******************************************************************/
  252.  
  253. /*
  254.          ---------------- General notes  ------------------------
  255.  
  256. SRE-FILTER  call this procedure when the POST_FILTER variable is set to YES.
  257.  
  258. 6 arguments are passed here:
  259.     amessage
  260.     source
  261.     request
  262.     sel0
  263.     tempfile
  264.     params
  265.  
  266. Amessage 
  267.     is generated by SRE-FILTER, and indicates what SRE-FILTER did with this request.
  268.  
  269. Source,request,and sel0 are generated by GoServe, and contain:
  270.  
  271.   Source 
  272.        serveraddr serverport transaction_number clientaddr clientport
  273.   Request
  274.     verb uri protocol 
  275.   Sel0
  276.     action '?' awords  (?awords may not be present
  277.  
  278. Tempfile is set in SRE-FILTER
  279.   Tempfile
  280.     A temporary file name. It may have been used to construct the response, so you probably should
  281.     delete it first (use SYSFILEDELETE(TEMPFILE) ).
  282.  
  283. Params
  284.    Are optional parameters sent by SRE-FILTER.  Currently, it contains the name of the
  285.    SMTP gateway (set in the SMTP_GATEWAY variable of SRE-FILTER).
  286.  
  287. Example:
  288.      message               HTML File sent:/INDEX.HTM
  289.      Source                151.121.65.143 80 3 219.134.78.12 1026
  290.      request                GET /sampask2.htm HTTP/1.0
  291.      sel0                   sampask2.htm
  292.      tempfile               D:/GOHTTP/$10.80
  293.      params                mail.myprovider.net
  294.  
  295.  
  296. Note on Amessage:
  297.   The folllowing lists the "messages" that SRE-FILTER may send.  Note that the ||varname
  298.   means the value of Varname is appended to the message.  Also note that when varname=SEL,
  299.   the SEL may be different then SEL0 (say, if a ~ replacement occurred).
  300.  
  301.     Pre-filter used
  302.     Cached file sent: ||sel0
  303.     Bad HTTP Protocol
  304.     Unauthorized access
  305.     No client name found, access denied
  306.     Logon denied to non-inhouse user
  307.     Pre-filter used
  308.     Alias invoked permanent redirect
  309.     Alias invoked temporary redirect
  310.     Transfered non-data directory file
  311.     Access to file denied:  ||sel
  312.     Ping request
  313.     CONTROL Statistics request
  314.     Host request
  315.     Control Moveaudit
  316.     Control Reset all
  317.     Variable display
  318.     !Special request denied: ||sel
  319.     Message box access
  320.     Message box access denied
  321.     Message box viewing
  322.     Special request processing unknown:||sel
  323.     HEAD request: Document not found:  ||sel0
  324.     Head request
  325.     Document not found
  326.     Server is busy
  327.     Non-HTML File sent:||file
  328.     HTML File sent:||file
  329.     HTML File sent (with ssi):||file
  330.     Mappable image request:'||foo
  331.     GET request:||action
  332.     Server busy
  333.     POST error: too much data
  334.     POST error: could not read data
  335.     POST request:||sel
  336.     POST problem:||sel
  337.     CGI-BIN access||sel
  338.  
  339. **************************************************************************/
  340.  
  341.